import React from "react";
import {ButtonType} from "antd/lib/button";
import {SizeType} from "antd/lib/config-provider/SizeContext";

declare const Placements: [
  "topLeft",
  "topCenter",
  "topRight",
  "bottomLeft",
  "bottomCenter",
  "bottomRight"
];

export type DropdownPlacement = typeof Placements[number];

export interface IExtraData {
  code: string;
  name: string;
  disabled?: boolean;
}

export interface IPermissionData {
  useHidden?: boolean;
  permissionCode?: string | string[];
}

export interface FuncProps extends IPermissionData {
  disabled?: boolean;
  key: string;
  para?: any;
  extraDatas?: IExtraData[]; // 额外选项，例如作废原因，会渲染为menuItem
  type?: ButtonType | "customize";
  icon?: React.ReactNode;
  size?: SizeType;
  className?: string;
  text?: string | React.ReactNode;
  title?: string;
  isPadding?: boolean;
  confirmTitle?: string;
  confirmMsg?: string;
  onClick?: (para?: any, extra?: any) => void;
  dropdownVisible?: boolean;
  shortcut?: (visible: boolean) => void;
}

export interface FuncGroupsMoreProps extends FuncProps {
  btns: FuncProps[];
}

export type THtmlType = "button" | "a";

export interface FuncGroupsProps {
  htmlType: THtmlType;
  placement?: DropdownPlacement;
  btns: (FuncProps | FuncGroupsMoreProps)[];
}

export function isFuncGroupsMoreProps(object: any): object is FuncGroupsProps {
  return !!object.btns;
}
